package com.wyz.saas.common.view.airpanel

import android.util.AttributeSet
import android.view.View
import com.wyz.saas.common.R


class AirAttribute {
    var panelMinHeight = 0
    var panelMaxHeight = 0
    companion object{
        fun obtain(
            view: View, attrs: AttributeSet?,
            defStyleAttr: Int, defStyleRes: Int,
            attrValues: IntArray?, attrMinIndex: Int, attrMaxIndex: Int
        ): AirAttribute {
            val a = view.context.obtainStyledAttributes(attrs,
                    attrValues!!, defStyleAttr, defStyleRes
                )
            val resources = view.resources
            val minHeight = a.getDimensionPixelOffset(
                attrMinIndex,
                resources.getDimensionPixelOffset(R.dimen.airPanelMinHeight)
            )
            val maxHeight = a.getDimensionPixelOffset(
                attrMaxIndex,
                resources.getDimensionPixelOffset(R.dimen.airPanelMaxHeight)
            )
            a.recycle()
            val attribute = AirAttribute()
            attribute.panelMinHeight = minHeight
            attribute.panelMaxHeight = maxHeight
            return attribute
        }
    }

    override fun toString(): String {
        return "AirAttribute(panelMinHeight=$panelMinHeight, panelMaxHeight=$panelMaxHeight)"
    }

}